package client.gui;

import javax.swing.*;

import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;


import client.ChatClient;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import sharedspace.*;

/**
 * This JFrame is a frame to show the test
 * @author Amir S.
 * @author Jacob C.
 * @author Maya G.
 * @author Michael V.
 *
 */

public class GUI_Test_View extends JFrame{
	
	private Toolkit toolkit = Toolkit.getDefaultToolkit();
	private Dimension scrnsize = toolkit.getScreenSize();
	private ArrayList<QuestionInTest> qitList = null;
	private JLabel question = null;
	private JRadioButton answer = null;
	private JPanel form = null;
	private JScrollPane scroller = null;
	
	
	public GUI_Test_View(ArrayList<QuestionInTest> qit) {
		super();
		this.qitList = qit;
		initialize();	
	}

	/**
	 * This method initializes the Main screen . 
	 */
	private void initialize() {
		
		this.setSize(600, 800);
		this.setLocation((toolkit.getScreenSize().width-600)/2, (toolkit.getScreenSize().height-800)/2);
		this.setTitle("Test");
		this.setLayout(null);

		displayTest();
		this.add(scroller,null
				);

	}

	public void displayTest()
	{
		
		// set all student choices in test to -1 (if choice is -1 student didn't answer question) 
		
		// making new JPanel for test
		form = new JPanel(new VerticalLayout(50, VerticalLayout.LEFT));
		form.setBackground(Color.WHITE);

		for( int i = 0; i<qitList.size(); i++)//insert question to JPanel
		{
			JPanel qPanel = new JPanel(new VerticalLayout(0, VerticalLayout.LEFT));
			qPanel.setBackground(Color.WHITE);
			question = new JLabel((i+1)+". "+qitList.get(i).getQuestion().getQuestion());
			question.setFont(new Font("Arial",Font.PLAIN,32));
			question.setForeground(Color.BLACK);
			ButtonGroup buttonGroup = new ButtonGroup();
			qPanel.add(question);// insert question comment to question JPanel
			question = new JLabel(" " + qitList.get(i).getQuestion().getQuestionCommet());
			qPanel.add(question);// insert questionComment to question JPanel
			for (int j = 0; j<4; j++)
			{   
				answer = new JRadioButton((j+1)+".     "+qitList.get(i).getQuestion().getAnswers()[j]);
				answer.setActionCommand(Integer.toString(i));
				answer.setBackground(null);

				qPanel.add(answer);
				buttonGroup.add(answer);
			}
			
			
			form.add(qPanel);	
		}
		

		scroller= new JScrollPane(form);
		scroller.setBounds(new Rectangle(0, 0, 600, 800));
		
		
		
		//System.out.println("time is over");
		
		
	}
}
